//
//  MCNewAcWuYueViewController.m
//  ZXZX
//
//  Created by menhao on 2018/5/9.
//  Copyright © 2018年 TLYL01. All rights reserved.
//

#import "MCNewAcWuYueViewController.h"
#import "MCNewActGetMoneyModel.h"
#import "MCNewActCharModel.h"
#import "MCGetHeAcmodel.h"
@interface MCNewAcWuYueViewController ()

@property (nonatomic,weak) UILabel *myLabel;
@property (nonatomic,weak) UIButton *btn;
@property (nonatomic,strong) MCNewActGetMoneyModel *getMoneyModel;
@property (nonatomic,strong) MCNewActCharModel *charModel;
@property (nonatomic,strong) MCGetHeAcmodel *getHeAcmodel;
@property (nonatomic,weak) UIScrollView *bases;
@property (nonatomic,weak) UIView *bgVIew;
@property (nonatomic,weak) UIImageView *titleImageV;
@end

@implementation MCNewAcWuYueViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setUpUI];
    self.navigationItem.title = @"活动详情";
//    [self loadData];
}
-(void)setUpUI{
    
    self.automaticallyAdjustsScrollViewInsets = YES;
    self.view.backgroundColor = RGB(245, 245, 245);
    UIScrollView *bases = [[UIScrollView alloc] initWithFrame:self.view.bounds];
    [self.view addSubview:bases];
    
    bases.contentSize = CGSizeMake(G_SCREENWIDTH - MC_REALVALUE(26), G_SCREENHEIGHT);
    UIImageView *titleImageV = [[UIImageView alloc] init];
    [bases addSubview:titleImageV];
    self.titleImageV = titleImageV;
    titleImageV.image = [UIImage imageNamed:@"争霸赛.jpg"];
    
    [titleImageV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(bases).offset(13);
        make.width.equalTo(@(G_SCREENWIDTH - MC_REALVALUE(26)));
        make.height.equalTo(@(92));
        make.top.equalTo(bases).offset(13);
        
    }];
    UIImageView *coverImgV = [[UIImageView alloc] init];
    coverImgV.image = [UIImage imageNamed:@"hdyjs"];
    [bases addSubview:coverImgV];
    [coverImgV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(titleImageV);
    }];
    UILabel *titleLabel =  [[UILabel alloc] init];
    [bases addSubview:titleLabel];
    titleLabel.text = @"公测争霸赛";
    titleLabel.textAlignment = NSTextAlignmentLeft;
    titleLabel.textColor = RGB(249, 84, 83);
    titleLabel.font = [UIFont boldSystemFontOfSize:MC_REALVALUE(14)];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(titleImageV);
        make.top.equalTo(titleImageV.mas_bottom).offset(MC_REALVALUE(13));
        
    }];
    
    UILabel *titleSubLabel =  [[UILabel alloc] init];
    [bases addSubview:titleSubLabel];
    titleSubLabel.textAlignment = NSTextAlignmentLeft;
    titleSubLabel.text = @"活动时间：7月28日12时 --7月30日24时 ";
    titleSubLabel.textColor = RGB(99, 99, 99);
    titleSubLabel.font = [UIFont systemFontOfSize:MC_REALVALUE(12)];
    [titleSubLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(titleImageV);
        make.top.equalTo(titleLabel.mas_bottom).offset(MC_REALVALUE(13));
        
    }];
    
    
    UILabel *lineTitleLabel =  [[UILabel alloc] init];
    [bases addSubview:lineTitleLabel];
    lineTitleLabel.backgroundColor = RGB(136, 136, 136);
    [lineTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(titleImageV);
        make.top.equalTo(titleSubLabel.mas_bottom).offset(MC_REALVALUE(10));
        make.height.equalTo(@(0.5));
    }];
    
    
    UILabel *contentLabel =  [[UILabel alloc] init];
    [bases addSubview:contentLabel];
    contentLabel.text = @"活动内容：\n\n注册用户系统自带20000本金，在规定的活动时间内客户盈利排名，按照名次获取相应奖励，奖励将在平台正式开业后派发到玩家账户上，有任何疑问请联系在线客服。";
    contentLabel.textAlignment = NSTextAlignmentLeft;
    contentLabel.numberOfLines = 0;
    contentLabel.textColor = RGB(99, 99, 99);
    contentLabel.font = [UIFont systemFontOfSize:MC_REALVALUE(12)];
    [contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(titleImageV);
        make.top.equalTo(lineTitleLabel.mas_bottom).offset(MC_REALVALUE(10));
        
    }];
    UILabel *awTitleLabel =  [[UILabel alloc] init];
    [bases addSubview:awTitleLabel];
    awTitleLabel.text = @"活动奖金：";
    awTitleLabel.textAlignment = NSTextAlignmentLeft;
    awTitleLabel.textColor = RGB(99, 99, 99);
    awTitleLabel.font = [UIFont systemFontOfSize:MC_REALVALUE(12)];
    [awTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(titleImageV);
        make.top.equalTo(contentLabel.mas_bottom).offset(MC_REALVALUE(10));
        
    }];
    UIView *bgVIew = [[UIView alloc] init];
    [bases addSubview:bgVIew];
    [bgVIew mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(titleImageV);
        make.top.equalTo(awTitleLabel.mas_bottom).offset(MC_REALVALUE(10));
        make.height.equalTo(@(200));
    }];
    bgVIew.layer.borderWidth = 0.5;
    bgVIew.layer.borderColor = RGB(136, 136, 136).CGColor;
    
    NSArray *cArr = @[@"第1名",@"第2名",@"第3-10名",@"第11-100名",@"第101-300名"];
    for (NSInteger i = 0; i<cArr.count; i++) {
        UILabel *chongJinLabel = [[UILabel alloc] init];
        [bgVIew addSubview:chongJinLabel];
        chongJinLabel.textAlignment = NSTextAlignmentCenter;
        chongJinLabel.text = cArr[i];
        chongJinLabel.textColor = RGB(99, 99, 99);
        chongJinLabel.font = [UIFont systemFontOfSize:MC_REALVALUE(12)];
        chongJinLabel.layer.borderWidth = 0.25;
        chongJinLabel.layer.borderColor = RGB(136, 136, 136).CGColor;
        chongJinLabel.frame = CGRectMake(0, 40*i, 0.5*(G_SCREENWIDTH - MC_REALVALUE(26)), 40);
    }
    
    
    NSArray *jArr = @[@"奖励188888元 ",@"奖励88888元 ",@"奖励2888元",@" 奖励188元",@" 奖励58元"];
    for (NSInteger i = 0; i<jArr.count; i++) {
        UILabel *jiangLabel = [[UILabel alloc] init];
        [bgVIew addSubview:jiangLabel];
        jiangLabel.textAlignment = NSTextAlignmentCenter;
        jiangLabel.text = jArr[i];
        jiangLabel.textColor = RGB(99, 99, 99);
        jiangLabel.font = [UIFont systemFontOfSize:MC_REALVALUE(12)];
        jiangLabel.layer.borderWidth = 0.25;
        jiangLabel.layer.borderColor = RGB(136, 136, 136).CGColor;
        jiangLabel.frame = CGRectMake(0, 40*i, 0.5*(G_SCREENWIDTH - MC_REALVALUE(26)), 40);
        jiangLabel.frame = CGRectMake(0.5*(G_SCREENWIDTH - MC_REALVALUE(26)), 40*i, 0.5*(G_SCREENWIDTH - MC_REALVALUE(26)), 40);
    }
    
 
    
   
    
//    UILabel *infoLabel =  [[UILabel alloc] init];
//    [bases addSubview:infoLabel];
//    infoLabel.numberOfLines = 0;
//
//    infoLabel.textAlignment = NSTextAlignmentLeft;
//    infoLabel.textColor = RGB(99, 99, 99);
//
//    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:@"1.会员每日首笔充值达到相应金额，即可领取对应奖金，每日仅限前1000名。\n2.当日奖金应当日领取，逾期领取，视为放弃。\n3.成功领取金额后，需在当日23:59前消费【首充金额+赠送金额】的1倍流水方可出款，例如充值3000送38，需消费3038元算达标；未达到出款流水要求，次日将重新开始计算流水。\n4.本平台禁止一切违规对打套利行为，对此平台将实时监控，同一个ip，平台帐号，绑定的姓名以及卡号，每日只可参与一次；如有发现违规套利账户，将永久冻结。\n5.会员活动期间内，玩法投注不得超过该玩法投注总码的70%，即定位胆必须小于等于7注，二码必须小于等于70注，三码必须小于等于700注，四星必须小于等于7000注，五星必须小于等于70000注。如发现违规投注情况，均视作放弃本次活动。\n6.正信在线保留对此活动修改的权利。"];
//    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
//    [paragraphStyle setLineSpacing:5];//调整行间距
//    [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [attributedString length])];
//    infoLabel.attributedText = attributedString;
//    infoLabel.font = [UIFont systemFontOfSize:MC_REALVALUE(12)];
//    [infoLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.right.equalTo(titleImageV);
//        make.top.equalTo(guizeLabel.mas_bottom).offset(MC_REALVALUE(10));
//
//    }];
//
//        UILabel *myLabel =  [[UILabel alloc] init];
//        [bases addSubview:myLabel];
//        myLabel.numberOfLines = 0;
//        NSString *str = @"今日首充金额：0元 ，累计消费金额：0元，可领取：0元";
//        NSArray *number = @[@"0",@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9"];
//        myLabel.textColor = RGB(99, 99, 99);
//        NSMutableAttributedString *attributeString = [[NSMutableAttributedString alloc] initWithString:str];
//        for (int i = 0; i < str.length; i ++) {
//            NSString *a = [str substringWithRange:NSMakeRange(i, 1)];
//            if ([number containsObject:a]) {
//              [attributeString addAttributes:@{NSForegroundColorAttributeName:RGB(249, 84, 83),NSFontAttributeName:[UIFont systemFontOfSize:MC_REALVALUE(12)]} range:NSMakeRange(i, 1)];
//            }
//        }
//        self.myLabel = myLabel;
//        myLabel.attributedText = attributeString;
//        myLabel.textAlignment = NSTextAlignmentLeft;
//        myLabel.textAlignment = NSTextAlignmentCenter;
//        myLabel.font = [UIFont systemFontOfSize:MC_REALVALUE(12)];
//        [myLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.left.right.equalTo(titleImageV);
//            make.top.equalTo(infoLabel.mas_bottom).offset(MC_REALVALUE(10));
//    
//        }];
//    
    
//        UIButton *btn = [[UIButton alloc] init];
//        [bases addSubview:btn];
//        [btn mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.centerX.equalTo(bases);
//            make.top.equalTo(myLabel.mas_bottom).offset(MC_REALVALUE(10));
//            make.height.equalTo(@(40));
//            make.width.equalTo(@(80));
//        }];
//        btn.backgroundColor = [UIColor orangeColor];
//        [btn setTitle:@"立即领取" forState:UIControlStateNormal];
//        [btn addTarget:self action:@selector(btnCLick) forControlEvents:UIControlEventTouchUpInside];
//        self.btn = btn;
//        btn.userInteractionEnabled = NO;
    self.bases = bases;
    self.bgVIew = bgVIew;
}
- (void)loadData{
    
//    MCNewActGetMoneyModel *getMoneyModel = [[MCNewActGetMoneyModel alloc] init];
//    self.getMoneyModel = getMoneyModel;
//    [getMoneyModel refreashDataAndShow];
//    __weak typeof(self) weakself= self;
//    [BKIndicationView showInView:self.view];
//    getMoneyModel.callBackSuccessBlock = ^(id manager) {
//        NSString *str = @"";
//
//        if ([manager[@"ReturnMoney"] intValue] <=0) {
//            weakself.btn.backgroundColor = RGB(181, 181, 181);
//            weakself.btn.enabled = NO;
//            str =[NSString stringWithFormat:@"今日首充金额：%d元，可领取：0元",[manager[@"ReceiveMoney"] intValue]];
//        }else{
//            weakself.btn.backgroundColor = [UIColor orangeColor];
//            weakself.btn.enabled = YES;
//            str =[NSString stringWithFormat:@"今日首充金额：%d元，可领取：%@元",[manager[@"ReceiveMoney"] intValue],GetRealSNum(manager[@"ReturnMoney"])];
//        }
//        NSArray *number = @[@"0",@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9"];
//        NSMutableAttributedString *attributeString = [[NSMutableAttributedString alloc] initWithString:str];
//        for (int i = 0; i < str.length; i ++) {
//            NSString *a = [str substringWithRange:NSMakeRange(i, 1)];
//            if ([number containsObject:a]) {
//                [attributeString addAttributes:@{NSForegroundColorAttributeName:RGB(249, 84, 83),NSFontAttributeName:[UIFont systemFontOfSize:MC_REALVALUE(12)]} range:NSMakeRange(i, 1)];
//            }
//        }
//        weakself.myLabel.attributedText = attributeString;
//
//    };
//    getMoneyModel.callBackFailedBlock = ^(ApiBaseManager *manager, NSDictionary *errorCode) {
//        if ([manager.responseMessage isEqualToString:@""]||manager.responseMessage == nil) {
//            return ;
//        } else {
//            [SVProgressHUD showInfoWithStatus:manager.responseMessage];
//        }
//    };
//
//
    
    MCGetHeAcmodel *getHeAcmodel = [[MCGetHeAcmodel alloc] init];
    self.getHeAcmodel = getHeAcmodel;
    [getHeAcmodel refreashDataAndShow];
    WS(wslf);
    getHeAcmodel.callBackFailedBlock = ^(ApiBaseManager *manager, NSDictionary *errorCode) {
        [SVProgressHUD showInfoWithStatus:manager.responseMessage];
    };
    getHeAcmodel.callBackSuccessBlock = ^(ApiBaseManager *manager) {
        
        NSArray *arr = [MCGetHeAcmodel mj_objectArrayWithKeyValuesArray:manager.ResponseRawData];
        
        [wslf setPaiMing:arr];
    };
}



- (void)setPaiMing:(NSArray *)jArr{
    if (jArr.count == 0) {
        
        UILabel *guizeLabel =  [[UILabel alloc] init];
        [self.bases addSubview:guizeLabel];
        guizeLabel.text = @"本活动最终解释权归正信在线所有！";
        guizeLabel.textAlignment = NSTextAlignmentLeft;
        guizeLabel.textColor = RGB(46, 46, 46);
        guizeLabel.font = [UIFont systemFontOfSize:MC_REALVALUE(11)];
        [guizeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.equalTo(self.titleImageV);
            make.top.equalTo(self.bgVIew.mas_bottom).offset(MC_REALVALUE(10));
            
        }];
        return;
    }
    UIView *paimingbgView = [[UIView alloc] init];
    [self.bases addSubview:paimingbgView];
    [paimingbgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view).offset(20);
        make.top.equalTo(self.bgVIew.mas_bottom).offset(MC_REALVALUE(70));
        make.right.equalTo(self.view).offset(-20);
        make.height.equalTo(@(30));
    }];
    
    UIImageView *paiMingImgV = [[UIImageView alloc] init];
    paiMingImgV.image = [UIImage imageNamed:@"jiangb"];
    [paimingbgView addSubview:paiMingImgV];
    [paiMingImgV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(paimingbgView).offset(10);
        make.top.equalTo(paimingbgView);
        make.width.height.equalTo(@(25));
    }];
    UILabel *paimingLabel = [[UILabel alloc] init];
    [paimingbgView addSubview:paimingLabel];
    paimingLabel.textAlignment = NSTextAlignmentCenter;
    paimingLabel.text = @"盈利排名";
    paimingLabel.textColor = RGB(99, 99, 99);
    paimingLabel.font = [UIFont systemFontOfSize:MC_REALVALUE(16)];
    
    [paimingLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(paiMingImgV.mas_right).offset(10);
        make.centerY.equalTo(paiMingImgV);
        
    }];
     int lineH = 40;
    long count = jArr.count;
    UIView *paimingContView = [[UIView alloc] init];
    [self.bases addSubview:paimingContView];
    [paimingContView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view).offset(20);
        make.top.equalTo(paimingbgView.mas_bottom).offset(MC_REALVALUE(30));
        make.right.equalTo(self.view).offset(-20);
        make.height.equalTo(@(lineH * count));
    }];
    
   self.bases.contentSize = CGSizeMake(G_SCREENWIDTH - MC_REALVALUE(26), G_SCREENHEIGHT + lineH * count);
    int j = 0;
    int k = 0 ;
    for (NSInteger i = 0; i<count; i++) {
        MCGetHeAcmodel *model = jArr[i];
        UIView *cellView = [[UIView alloc] init];
        [paimingContView addSubview:cellView];
        
        if (i%2 != 0) {
            
            cellView.frame = CGRectMake(0.5*(G_SCREENWIDTH - 40), k*lineH, 0.5*(G_SCREENWIDTH - 40), lineH);
            k++;
        } else {
            
            cellView.frame = CGRectMake(0, j*lineH, 0.5*(G_SCREENWIDTH - 40), lineH);
            j++;
        }
        
        
        UIImageView *paiMingImgV = [[UIImageView alloc] init];
        NSString *imageName = @"";
        if (i==0) {
            imageName = @"bzb";
        } else if (i==1)  {
            imageName = @"bza";
        }else if (i==2)  {
            imageName = @"bzc";
        }else {
            imageName = @"bzd";
        }
        paiMingImgV.image = [UIImage imageNamed:imageName];
        [cellView addSubview:paiMingImgV];
        [paiMingImgV mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(cellView).offset(10);
            make.centerY.equalTo(cellView);
            make.width.height.equalTo(@(25));
        }];
        UILabel *label = [[UILabel alloc] init];
        [paiMingImgV addSubview:label];
        label.textAlignment = NSTextAlignmentCenter;
        label.text = [NSString stringWithFormat:@"%ld",i+1];
        label.textColor = RGB(255, 255, 255);
        label.font = [UIFont systemFontOfSize:MC_REALVALUE(10)];
        [label mas_makeConstraints:^(MASConstraintMaker *make) {
            make.center.equalTo(paiMingImgV);
        }];
        UILabel *jiangLabel = [[UILabel alloc] init];
        [cellView addSubview:jiangLabel];
        jiangLabel.textAlignment = NSTextAlignmentCenter;
        
        jiangLabel.textColor = RGB(99, 99, 99);
        jiangLabel.font = [UIFont systemFontOfSize:MC_REALVALUE(12)];
        [jiangLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(paiMingImgV.mas_right);
            make.centerY.equalTo(paiMingImgV);
        }];
        jiangLabel.text = model.UserName;
        UILabel *jinLabel = [[UILabel alloc] init];
        [cellView addSubview:jinLabel];
        jinLabel.textAlignment = NSTextAlignmentCenter;
       
        jinLabel.textColor = [UIColor redColor];
        jinLabel.font = [UIFont systemFontOfSize:MC_REALVALUE(12)];
        [jinLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(jiangLabel.mas_right);
            make.centerY.equalTo(jiangLabel);
        }];
        jinLabel.text = model.LossMoney;
    }
    

    UILabel *guizeLabel =  [[UILabel alloc] init];
    [self.bases addSubview:guizeLabel];
    guizeLabel.text = @"本活动最终解释权归正信在线所有！";
    guizeLabel.textAlignment = NSTextAlignmentLeft;
    guizeLabel.textColor = RGB(46, 46, 46);
    guizeLabel.font = [UIFont systemFontOfSize:MC_REALVALUE(11)];
    [guizeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.titleImageV);
        make.top.equalTo(self.bgVIew.mas_bottom).offset(MC_REALVALUE(10));
        
    }];
}
- (void)btnCLick{
    MCNewActCharModel *charModel = [[MCNewActCharModel alloc] init];
    self.charModel = charModel;
    [charModel refreashDataAndShow];
    __weak typeof(self) weakself= self;
    [BKIndicationView showInView:self.view];
    charModel.callBackSuccessBlock = ^(id manager) {
        [SVProgressHUD showInfoWithStatus:manager[@"Remarks"]];
        if ([manager[@"ReturnMoney"] intValue] == 1) {
            
            [weakself loadData];
        }
    };
    charModel.callBackFailedBlock = ^(ApiBaseManager *manager, NSDictionary *errorCode) {
        if ([manager.responseMessage isEqualToString:@""]||manager.responseMessage == nil) {
            return ;
        } else {
             [SVProgressHUD showInfoWithStatus:manager.responseMessage];
        }
       
    };
}
@end


